//
//  MainTabBarManager.swift
//  iOSProjectExtensionSwift
//
//  Created by HBGG on 2020/7/4.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import UIKit

class NavigationItem: NSObject {
    var viewController = UIViewController()
    var title = String()
    var normalImage = String()
    var selectImage = String()
}

class MainTabBarManager: NSObject {
    static var instance = MainTabBarManager()
    private override init() {
        
    }
    public func getAllNavigationControllers() ->(allNavs:Array<CCNavigationController>,viewArr:Array<UIViewController>) {
        let mainItem = NavigationItem.init()
        let mainVc = MainViewController.init()
        mainItem.viewController = mainVc;
        mainItem.title = "首页";
        mainItem.normalImage = "home_copy";
        mainItem.selectImage = "home2_copy";
        let mainNaVc = self.createNavWithVc(mainItem)
        
        let categoryItem = NavigationItem.init()
        let category = CategoryViewController.init()
        categoryItem.viewController = category;
        categoryItem.title = "分类";
        categoryItem.normalImage = "category_copy";
        categoryItem.selectImage = "category2_copy";
        let categoryNaVc = self.createNavWithVc(categoryItem)
        
        let cartItem = NavigationItem.init()
        let cart = CartViewController.init()
        cartItem.viewController = cart;
        cartItem.title = "购物车";
        cartItem.normalImage = "cart_copy";
        cartItem.selectImage = "cart2_copy";
        let cartNaVc = self.createNavWithVc(cartItem)
        
        let myItem = NavigationItem.init()
        let myView = MineViewController.init()
        myItem.viewController = myView;
        myItem.title = "我的";
        myItem.normalImage = "my_copy";
        myItem.selectImage = "my2_copy";
        let myNaVc = self.createNavWithVc(myItem)
        
        let controllers = [mainNaVc,categoryNaVc,cartNaVc,myNaVc]
        return (allNavs:controllers,viewArr:[mainVc, category, cart, myView])
    }
    private func createNavWithVc(_ item:NavigationItem) ->CCNavigationController{
        item.viewController.hidesBottomBarWhenPushed = false
        item.viewController.title = item.title
        let navigationController = CCNavigationController.init(rootViewController: item.viewController)
        let normalImage = UIImage(named: item.normalImage)?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
        let selectImage = UIImage(named: item.selectImage)?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
        navigationController.tabBarItem.image = normalImage
        navigationController.tabBarItem.selectedImage = selectImage
        return navigationController
    }
}
